package com.ocom.mqsimple.controller;

import com.alibaba.fastjson.JSON;
import com.ocom.common.constant.MqSimpleApiUrl;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.enums.ccbzhsh.CCBZHSHMqTypeEnum;
import com.ocom.common.request.simple.ccbzhsh.CCBZHSHMqBaseRequest;
import com.ocom.common.request.simple.ccbzhsh.CCBZHSHNewPersonInfoRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.mqsimple.business.ccbzhsh.impl.CCBZHSHProductServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CCBZZHSHController {

	private final Logger logger = LoggerFactory.getLogger(CCBZZHSHController.class);

	@Autowired
	private CCBZHSHProductServiceImpl ccbZHSHProductService;

	@PostMapping(MqSimpleApiUrl.URL_CCBZHSHMqAccessRecord)
	public Result newPersonInfo(@RequestBody CCBZHSHNewPersonInfoRequest request){
		try {
			CCBZHSHMqBaseRequest baseRequest = new CCBZHSHMqBaseRequest();
			baseRequest.setType(CCBZHSHMqTypeEnum.NEW_PERSONINFO.getValue());
			baseRequest.setMessage(JSON.toJSONString(request));
			ccbZHSHProductService.handle(JSON.toJSONString(baseRequest));
		}catch (Exception e){
			logger.error("发送mq失败  错误【{}】",e);
			return ResultUtil.error(ResultEnum.Err_4006);
		}
		return ResultUtil.success();
	}


}
